import React, { useEffect, useState, useRef } from "react";
import AntTabs from "~/public/cpas-ui/components-ui/ant-components/AntTab";
import { useModel } from 'umi';
import PageTabOne from "./tab1";
// import PageTabTwo from "./tab2";
import VerifySummary from '~/public/cpas-business/cpas-table/CpasNotes/verifySummary';
// import PageTabThree from "./tab3";
import "./index.less";

const ReportAnalysis = () => {
  const { initialState } = useModel('@@initialState');
  const [tabText1, setTabText1] = useState("");
  const tabsRef: any = useRef(null);
  const tabRef: any = useRef(null);
  const [isRerun, setIsRerun] = useState(false);
  const [activeKey, setActiveKey] = useState("1")
  const AccountTabsClick = (key: string) => {
    console.log(key, 'key----');
    if (key === '2') {
      setIsRerun(false);
    }
    setTabText1(key)
    setActiveKey(key);
  };
  const modileIsReturn = (value: any) => {
    setIsRerun(value);
  };
  useEffect(() => {
    AccountTabsClick('1');
  }, []);
  useEffect(() => {
    console.log(isRerun, 'isRerun---useEffect');
    const notePageRef = tabRef?.current?.notePageRef;
    if (isRerun && tabText1 === "1" && notePageRef?.current?.tab1Init) {
      notePageRef.current.tab1Init();
    }
  }, [isRerun, tabText1]);
  /**
   *
   * @param data
   * @param noVerifyModal 是否打开校验详情弹窗
   */
  const openVerifyDetail = (data: any, noVerifyModal: boolean) => {
    const notePageRef = tabRef?.current?.notePageRef;
    console.log("opendetail---tabsRef", tabsRef);
    console.log(data, 'openDetail data');
    setActiveKey("1");
    // AccountTabsClick('1');
    notePageRef.current.openVerifyDetail(data, noVerifyModal);
    notePageRef.current.tab1SearchTableName(data.title, data.fid);
  }
  return (
    <div>
      <AntTabs
        tabBarStyle={{ background: '#FFF' }}
        onChange={AccountTabsClick}
        className={"report-analysis-tabs"}
        defaultActiveKey="1"
        ref={tabsRef}
        activeKey={activeKey}
      >
        <AntTabs.Panel
          tab='附注'
          key='1'
        >
          <PageTabOne ref={tabRef} />
        </AntTabs.Panel>
        <AntTabs.Panel
          className={"art-count-panel"}
          tab='附注勾稽汇总'
          key='2'
        >
          <VerifySummary modileIsReturn={modileIsReturn} type="ds" storageName="dbNameData" title="附注勾稽关系汇总" openVerifyDetail={openVerifyDetail} dbname={initialState?.curPart?.dbname} activeTabKey={activeKey} />
          {/* 开发中。。。 */}
        </AntTabs.Panel>
        {/*<AntTabs.Panel*/}
        {/*  tab='附注波动分析'*/}
        {/*  key='3'*/}
        {/*>*/}
        {/*  /!* <PageTabThree/> *!/*/}
        {/*  开发中。。。*/}
        {/*</AntTabs.Panel>*/}
      </AntTabs>
    </div>
  );
};
export default ReportAnalysis;
